package 迭代器设计模式;

import java.util.List;

/**
 * 抽象迭代器
 */
public class ConcreteIterator implements Iterator {

    private List list;

    private int index = 0;

    public ConcreteIterator(List list) {
        this.list = list;
    }

    @Override
    public Object next() {
        Object obj = null;
        if (hasNext()) {
            obj = list.get(index);
            index++;
        }
        return obj;
    }

    @Override
    public boolean hasNext() {
        return list.size() != index;
    }

    @Override
    public Object remove(Object o) {
        return list.remove(o);
    }
}
